package org.hot100_6.leetcode560;

public class Solution {
    public int subarraySum(int[] nums, int k) {

        int n = nums.length;

        int [] preSum = new int[n+1];
        preSum[0]=0;
        for (int i = 1; i <= n; i++) {
            preSum[i]=preSum[i-1]+nums[i-1];
        }

        int count = 0;

        for (int left = 0; left <=n; left++) {
            for (int right = left+1; right <= n; right++) {
                if (preSum[right]-preSum[left]==k){
                    count++;
                }
            }
        }
        return count;
    }
}
